package top.xiaozhaobk.xiaofenshu.oss.biz.exception;


import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import top.xiaozhaobk.framework.common.response.Response;
import top.xiaozhaobk.xiaofenshu.oss.biz.enums.ResponseCodeEnum;

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(value = RuntimeException.class)
    @ResponseBody
    public Response<Object> handleBizException(HttpServletRequest request, RuntimeException e) {
        log.error("==> 业务异常处理, url: {}, message: {}", request.getRequestURI(), e.getMessage());
        return Response.fail(ResponseCodeEnum.PARAM_NOT_VALID);
    }

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Response<Object> handleOtherException(HttpServletRequest request, Exception e) {
        log.error("==> 全局异常处理, url: {}, message: {}", request.getRequestURI(), e.getMessage());
        return Response.fail(ResponseCodeEnum.SYSTEM_ERROR);
    }
}
